home *** CD-ROM | disk | FTP | other *** search
- ;void set_mem_16(replacement,position,bits,segment,offset);
- ; unsigned short replacement,segment,offset;
- ; unsigned char position,bits;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _set_mem_16
- _set_mem_16 proc near
- push bp ;
- mov bp,sp ;make stack frame
- push di ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: mov _error_code,0 ;clear _error_code
- les di,dword ptr[bp+12] ;ES:DI pts to memory
- mov cl,[bp+8] ;number bits
- inc _error_code ;1 = zero bits
- or cl,cl ;error check
- jz L1 ;quit if zero bits
- mov dx,0FFFFH ;all 1s in DL
- shl dx,cl ;field-width of 0s
- not dx ;field-width of 1s
- mov ax,[bp+4] ;replacement value
- and ax,dx ;clear superfluous bits
- mov bl,cl ;copy Bits to BL
- mov cl,[bp+6] ;Position
- inc _error_code ;2 = position out of range
- cmp cl,15 ;greater than 15?
- ja L1 ;quit if so
- add bl,cl ;add number bits
- inc _error_code ;3 = field too large
- cmp bl,16 ;does it fit?
- ja L1 ;quit if error
- shl ax,cl ;shift value to position
- shl dx,cl ;shift mask to position
- not dx ;reverse mask
- and es:[di],dx ;clear field
- or es:[di],ax ;write new bits
- mov _error_code,0 ;success, return 0
- L1: pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _set_mem_16 endp
- _TEXT ENDS
- END